function MainAssistant() {

}

MainAssistant.prototype.setup = function() {
	depot.init();
	eliza.mainAssistant = this;
	eliza.init();
	
	this.controller.setupWidget(Mojo.Menu.appMenu, {
		omitDefaultItems: true
		}, 
		{
            visible: true,
            items: [ 
                { label: "Reset", command: 'do-reset'},
                { label: "Customize AI", items: [
                                                 { label: "Initials", command: 'do-customize-initials' },
                                                 { label: "Finals", command: 'do-customize-finals' },
                                                 { label: "Quits", command: 'do-customize-quits' },
                                                 { label: "Synonyms", command: 'do-customize-synonyms' },
                                                 { label: "Keywords", command: 'do-customize-keywords' },
                                                 { label: "Restore Defaults", command: 'do-restore-defaults' }
                   ]
                }
            ]
		}
	);
	
	this.controller.setupWidget("chatScroller",
	         this.chatScrollerAttributes = {
	             mode: 'vertical'
	         },
	         this.chatScrollerModel = {
	         });

	
	this.controller.setupWidget("chatBox", this.chatBoxAttributes = {
		multiline : true,
		enterSubmits : false,
// preventResize : true,
// limitResize: true
	}, this.chatBoxModel = {
		value : "",
		disabled : true
	});
	this.controller.setupWidget("inputBox", this.inputBoxAttributes = {
		multiline : false,
		enterSubmits : true,
		requiresEnterKey : true,
		autoFocus : false
	}, this.inputBoxModel = {
		value : "",
		disabled : false
	});

	this.inputBox = this.controller.get("inputBox");
	this.chatBox = this.controller.get("chatBox");
	this.chatScroller = this.controller.get("chatScroller");
	Mojo.Event.listen(this.inputBox, Mojo.Event.propertyChange,
			this.handleSubmit);
	this.controller.getSceneScroller().mojo.revealBottom();
	
	this.chatBoxModel.value = "\nChatty: " + eliza.initial();
};

MainAssistant.prototype.handleSubmit = function(event) {
	eliza.mainAssistant.submit(event.value);
};

MainAssistant.prototype.handleCommand = function(event) {
    if (event.type == Mojo.Event.command) {
        switch (event.command) {
        	case "do-reset":
        		eliza.mainAssistant.reset();
        		break;
        	case 'do-customize-initials':
        		eliza.mainAssistant.controller.stageController.pushScene("customize-initials", "Customize Initials", elizaInitials, this.setInitials);
        		break;
        	case 'do-customize-finals':
        		eliza.mainAssistant.controller.stageController.pushScene("customize-initials", "Customize Finals", elizaFinals, this.setFinals);
        		break;
        	case 'do-customize-quits':
        		eliza.mainAssistant.controller.stageController.pushScene("customize-initials", "Customize Quits", elizaQuits, this.setQuits);
        		break;
        	case 'do-restore-defaults':
        		elizaInitials = elizaInitialsRestore;
        		elizaFinals = elizaFinalsRestore;
        		elizaQuits = elizaQuitsRestore;
        		elizaPres = elizaPresRestore;
        		elizaPosts = elizaPostsRestore;
        		elizaSynons = elizaSynonsRestore;
        		elizaKeywords = elizaKeywordsRestore;
        		depot.removeAll();
//        		depot.init();
        		eliza.mainAssistant.reset();
        		break;
            default: Mojo.Log.info(event.command);
        }
    }
};

MainAssistant.prototype.setInitials = function(value) {
	elizaInitials = value;
	depot.add("elizaInitials", elizaInitials);
	eliza.mainAssistant.reset();
};

MainAssistant.prototype.setFinals = function(value) {
	elizaFinals = value;
	depot.add("elizaFinals", elizaFinals);
	eliza.mainAssistant.reset();
};

MainAssistant.prototype.setInitials = function(value) {
	elizaQuits = value;
	depot.add("elizaQuits", elizaQuits);
	eliza.mainAssistant.reset();
};


MainAssistant.prototype.reset = function() {
	eliza.reset();
	this.chatBox.mojo.setValue("\nChatty: " + eliza.initial());
};

MainAssistant.prototype.submit = function(text) {
	if (text.trim() == "") {
		return;
	}
	this.chatBox.mojo.setValue(this.chatBox.mojo.getValue() + "\nYou: " + text
			+ "\nChatty: " + eliza.transform(text));
	this.inputBox.mojo.setValue("");
	this.inputBox.mojo.focus();
// this.inputBox.mojo.blur();
	this.chatScroller.mojo.revealBottom();
};

MainAssistant.prototype.deactivate = function(event) {
	/*
	 * remove any event handlers you added in activate and do any other cleanup
	 * that should happen before this scene is popped or another scene is pushed
	 * on top
	 */
	Mojo.Event.stopListening(this.inputBox, Mojo.Event.propertyChange,
			this.handleSubmit);
};

MainAssistant.prototype.cleanup = function(event) {
	/*
	 * this function should do any cleanup needed before the scene is destroyed
	 * as a result of being popped off the scene stack
	 */
};
